﻿using System;
using RepositoryAndEf.Core.Data;
using Moq;
using Xunit;
using FluentAssertions;
using RepositoryAndEf.Data;


namespace RepositoryAndEf.Domain.Tests
{
    public class UserServiceTests
    {
        private IRepository<User> _userRepository = new MockRepository<User>();

        [Fact]
        public void RegisterUser_ExpectedParameters_Success()
        {
            var userService = new UserService(_userRepository);
            var registeredUser = userService.Register(
                "hellojesseliu@outlook.com",
                "Jesse",
                "Jesse");

            var userFromRepository = _userRepository.GetById(registeredUser.Id);

            userFromRepository.Should().NotBe(null);
            userFromRepository.Email.Should().Be("hellojesseliu@outlook.com");
            userFromRepository.Name.Should().Be("Jesse");
            userFromRepository.Password.Should().Be("Jesse");
        }

        [Fact]
        public void RegisterUser_ExistedEmail_ThrowException()
        {
            var userService = new UserService(_userRepository);
            var registeredUser = userService.Register(
                "hellojesseliu@outlook.com",
                "Jesse",
                "Jesse");

            var userFromRepository = _userRepository.GetById(registeredUser.Id);
            userFromRepository.Should().NotBe(null);

            Action action = () => userService.Register(
                "hellojesseliu@outlook.com",
                "Jesse_01",
                "Jesse");
            action.ShouldThrow<ArgumentException>();
        }
    }
}

